<?php 
//获取版块全部统计信息
function getTotalCount( $tree, $totalCount , $class , $type ){
	$child	=	array();
	getChildTagId(array( $tree ),$child);
	
	foreach( $child as $value ){
		$theme[] = $totalCount[$value]['theme'];
		$reply[] = $totalCount[$value]['reply'];
	}
	$data['theme'] = array_sum( $theme );
	$data['reply'] = array_sum( $reply );
	return $data[$type];
}

//获取版块今天统计信息
function getTodayCount( $tree , $totalCount , $class , $type ){
	$child	=	array();
	getChildTagId(array( $tree ),$child);
	
	foreach( $child as $value ){
		$theme[] = $totalCount[$value]['theme'];
		$reply[] = $totalCount[$value]['reply'];
	}
	$data['theme'] = array_sum( $theme );
	$data['reply'] = array_sum( $reply );
	return $data[$type];
}

function getChildTagId($tree,&$child=array()) {
	foreach($tree as $v){
		$child[]	=	$v[a];
		if(is_array($v[d])){
			getChildTagId($v[d],$child);
		}
	}
}

function getBBSContent( $content ){
	return str_replace( array('[quote]','[/quote]'),array('<div class="rela"><blockquote>','</blockquote></div>'),$content );
}

function getQuoteContent( $content ){
	$content = preg_replace("/\[quote\](.+?)\[\/quote\]/is","",$content); 
	$content = strip_tags($content);
	return msubstr($content,0,100);
}

//取得Tag版块下的版主
function getBanzu($tagid){
	$info = D('Board')->where('tagid='.$tagid)->field('banzhu')->find();
	$info = explode(',',$info['banzhu']);
	$info = array_map('getUserName',$info);
	return implode(',',$info);
}

function getTclassName( $classid ){
	$info = M('bbs_tclass')->where('id='.$classid)->field('name')->find();
	if($info){
		return "[ ".$info['name']." ]";
	}
}

//将二维数组格式化为一维数组
function formatArray($array, $field = 'id') {
	$res = array();
	foreach($array as $v) {
		$res[] = $v[$field];
	}
	return $res;
}
?>